import numpy as np
import matplotlib.pyplot as plt


class IPA:
    def __init__(self,matrix1,matrix2):
        '''
        matrix1:所有用户对重要性的评价
        matrix2:所有用户对满意性的评价
        '''
        self.matrix1=np.array(matrix1)
        self.matrix2=np.array(matrix2)

        average_matrix2 = []

    def getaverage(self,matrix):
        m,n=matrix.shape
        list=[]
        for i in range(n):
            list.append(sum(matrix[:,i])/m)

        return list

    def getResult(self):
        plt.clf()
        average_matrix1 = self.getaverage(self.matrix1)
        average_matrix2 = self.getaverage(self.matrix2)
        ave1=sum(average_matrix1)/len(average_matrix1)
        ave2=sum(average_matrix2) / len(average_matrix2)
        plt.scatter(average_matrix1,average_matrix2)
        plt.axhline(y=ave1)
        plt.axvline(x=ave2)
        num=[i+1 for i in range(len(average_matrix1))]
        for i in range(len(num)):
            plt.annotate(num[i], xy=(average_matrix1[i], average_matrix2[i]), xytext=(average_matrix1[i] + 0.1, average_matrix2[i] + 0.1))
        #plt.show()



'''
a=[[1,2,4,5],[2,4,3,4]]
b=[[2,1,3,2],[3,2,2,1]]
c=IPA(a,b)
c.getResult()
'''
